package com.sxz.sbs.module.message.adapter;

import android.view.View;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sxz.sbs.R;
import com.sxz.sbs.applibrary.component.LabelTextView;
import com.sxz.sbs.module.message.mode.MessageBean;

import java.util.List;

/**
 * 消息列表适配器
 */

public class MessageAdapter extends BaseMultiItemQuickAdapter<MessageBean.ListBean,BaseViewHolder>{
    /**
     * 通知类
     */
    public static final int NOTICE_MESSAGE_TYPE = 1;
    /**
     * 审批类
     */
    public static final int APPROVE_MESSAGE_TYPE = 2;
    /**
     * 提醒类
     */
    public static final int WARN_MESSAGE_TYPE = 3;
    private OnMessageHandleListener onMessageHandleListener;

    /**
     * 点击监听
     * @param onMessageHandleListener
     */
    public void setOnMessageHandleListener(OnMessageHandleListener onMessageHandleListener) {
        this.onMessageHandleListener = onMessageHandleListener;
    }

    public MessageAdapter(List<MessageBean.ListBean> data) {
        super(data);
        addItemType(NOTICE_MESSAGE_TYPE, R.layout.item_notice_message_layout);
        addItemType(APPROVE_MESSAGE_TYPE, R.layout.item_approve_message_layout);
        addItemType(WARN_MESSAGE_TYPE, R.layout.item_warn_message_layout);
    }

    @Override
    protected void convert(final BaseViewHolder helper, final MessageBean.ListBean item) {
        switch (helper.getItemViewType()) {
            case NOTICE_MESSAGE_TYPE:
                helper.setText(R.id.tv_notice_message_date,item.getDate_SendTime());
                helper.setText(R.id.tv_notice_message_content,item.getTxt_Description());
                break;
            case APPROVE_MESSAGE_TYPE:
                helper.setText(R.id.tv_approve_message_date,item.getDate_SendTime());
                helper.setText(R.id.tv_approve_message_content,item.getTxt_Description());
                if (item.getVal_Status() != 1) {
                    helper.setText(R.id.tv_approve_message_title,"审批结果");
                    helper.setVisible(R.id.ll_approve_message_click,false);
                    helper.setVisible(R.id.tv_approve_message_result,true);
                    if (item.getVal_Status() == 2) {
                        helper.setVisible(R.id.ll_approve_message_click,true);
                        helper.setVisible(R.id.tv_approve_message_result,false);
                    }else if (item.getVal_Status() == 3) {
                        helper.setText(R.id.tv_approve_message_result,"已同意");
                    } else if(item.getVal_Status() == 4){
                        helper.setText(R.id.tv_approve_message_result,"已拒绝");
                    }
                } else {
                    helper.setText(R.id.tv_approve_message_title,"审批通知");
                    helper.setVisible(R.id.ll_approve_message_click,true);
                    helper.setVisible(R.id.tv_approve_message_result,false);
                }
                LabelTextView ltvRefuse = helper.getView(R.id.ltv_approve_message_refuse);
                LabelTextView ltvAgree = helper.getView(R.id.ltv_approve_message_agree);
                ltvAgree.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (onMessageHandleListener != null) {
                            onMessageHandleListener.onAgreeClick(v,helper.getAdapterPosition(),item);
                        }
                    }
                });
                ltvRefuse.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (onMessageHandleListener != null) {
                            onMessageHandleListener.onRefuseClick(v,helper.getAdapterPosition(),item);
                        }
                    }
                });
                break;
            case WARN_MESSAGE_TYPE:
                helper.setText(R.id.tv_warn_message_date,item.getDate_SendTime());
                helper.setText(R.id.tv_warn_message_content,item.getTxt_Description());
                break;
            default:
                break;
        }
    }
    public interface OnMessageHandleListener {
        /**
         * 点击拒绝
         * @param view
         * @param item
         */
        void onRefuseClick(View view,int position,MessageBean.ListBean item);

        /**
         * 点击同意
         * @param view
         * @param item
         */
        void onAgreeClick(View view,int position,MessageBean.ListBean item);
    }
}
